package com.chj.dfs.class04;

import java.util.ArrayList;
import java.util.List;

public class Code02_NodeToList {
	public static class Node {
		public int value;
		public Node next;

		public Node(int data) {
			this.value = data;
		}
	}

	public static List<Integer> addToVector(Node head, List<Integer> vec) {
		if (head == null) {
			return vec;
		}

		vec.add(head.value);
		return addToVector(head.next, vec);
	}

	public static void printLinkedList(Node node) {
		System.out.print("Linked List: ");
		while (node != null) {
			System.out.print(node.value + " ");
			node = node.next;
		}
		System.out.println();
	}

	public static void printArray(List<Integer> vec) {
		if (vec == null) {
			return;
		}
		for (int i = 0; i < vec.size(); i++) {
			System.out.print(vec.get(i) + " ");
		}
		System.out.println();
	}

	public static void main(String[] args) {
		Node node2 = new Node(1);
		node2.next = new Node(2);
		node2.next.next = new Node(3);
		node2.next.next.next = new Node(4);
		node2.next.next.next.next = new Node(5);
		printLinkedList(node2);

		List<Integer> vec = new ArrayList<>();

		vec = addToVector(node2, vec);
		printArray(vec);
	}
}
